#-*- coding:utf-8 -*-
"""
@Time:2020/9/1713:45
@Auth:DaiXvWen
@File:form.py
"""
from flask_wtf import FlaskForm
import wtforms
from wtforms import validators

#注册用户校验，账号必须为邮箱账号，密码必填
class RegisterForm(FlaskForm):
    username = wtforms.StringField(
        label="账号",
        validators=[
            validators.Email(message="不符合邮箱类型")
        ]
    )
    password = wtforms.StringField(label="密码",
                                   validators=[
                                       validators.Required(message="必填")
                                   ])

#添加与修改用户校验，用户名必填，密码必须为6-8位的数字
class AddPersonForm(FlaskForm):
    username = wtforms.StringField(validators=[
        validators.DataRequired(message="必填")
    ])
    password = wtforms.StringField(
        validators=[
            #使用正则约束密码，目前是失败的
            validators.Regexp('^[A-Za-z0-9]{5,15}$',message="以字母开头，长度在6-16之间，只能包含字符、数字和下划线")
        ]
    )
    nickname = wtforms.StringField(
        validators=[
            validators.DataRequired(message="必填")
        ]
    )
    age = wtforms.StringField(
        validators=[
            validators.Regexp('^[0-9]{1,2}$',message="只能输入99岁以内的年龄")
        ]
    )
    email = wtforms.StringField(
        validators=[
            validators.Email(message="请输入正确的邮箱格式")
        ]
    )

#部门添加与修改校验

class AddDepartmentForm(FlaskForm):
    d_name = wtforms.StringField(validators=[
        validators.DataRequired(message="必填")
    ])
    d_description = wtforms.StringField(
        validators=[
            validators.DataRequired(message="必填")
        ]
    )



#职位添加与修改校验

class AddPositionForm(FlaskForm):
    p_name = wtforms.StringField(validators=[
        validators.DataRequired(message="必填")
    ])
    p_level = wtforms.StringField(
        validators=[
            # validators.Length(min=6, max=8, message="密码不符合规则"),
            validators.Regexp('^[0-9]{6,8}$',message="密码为6到8位的数字")
        ]
    )
